package org.inasnet.frame;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.*;
import org.inasnet.Root;
import org.inasnet.util.*;


public class SettingsFrame extends JFrame 
{
	public SettingsFrame()
	{
		setTitle( Root.lang( "MAIN_Menu_Settings" ) );
		
		setLocation( 700, 300 );
		setSize( 300, 500 );
		
		setAlwaysOnTop( true );  
		
		setIconImage( Util.loadImage( "microphone_3.gif" ) );
		
		/*
		JMenu menu = new JMenu( Root.lang( "MAIN_Menu_Settings" ) );
		menuBar.add( menu );
		
		JMenuItem menuItem = new JMenuItem( Root.lang( "MAIN_Menu_Settings_Contacts" ) );
		menu.add( menuItem );
		
		menuItem = new JMenuItem( Root.lang( "MAIN_Menu_Settings_Profile" ) );
		menu.add( menuItem );
		
		menuItem = new JMenuItem( Root.lang( "MAIN_Menu_Settings_Connection" ) );
		menu.add( menuItem );
		*/
		
		/*
		 * Panel contact
		 */
		JPanel contactsPanel = new JPanel();
		contactsPanel.setLayout( new FlowLayout() );
		
		Object [][] rowData = new Object[ 2 ][ 2 ];
		for( int iterI = 0; iterI < rowData.length; iterI++ )
		{
			// Now user column
			rowData[ iterI ][ 0 ] = "weweew";
			
			for( int iterJ = 1; iterJ < rowData.length; iterJ++ )
			{
				rowData[ iterI ][ iterJ ] = new Integer( iterI * 2 + iterJ );
			}
		}
		
		String [] columnData = new String[ 2 ];
		columnData[ 0 ] = new String( "qq" );
		columnData[ 1 ] = new String( "qq!" );
			
		
		JTable table = new JTable( rowData, columnData ); 
		//table.setSize( , height)
		contactsPanel.add( table );
		//table.set
		/*
		 * End Panel contact
		 */
		
		
		JPanel connectionPanel = new JPanel();
		connectionPanel.setLayout( new FlowLayout() );
		
		javax.swing.ButtonGroup group = new ButtonGroup();
		
		
		mServerAddress = new JTextField();
		mServerAddress.setSize( getWidth() - 100, 25 );
		mServerAddress.setPreferredSize( new Dimension( getWidth() - 100, 25 ) );
		mServerAddress.setEnabled( false );
		
		
		
		JPanel languagePanel = new JPanel();
		
		File file = new File( "config/lang" );
		File [] langFiles = file.listFiles();
		
		ButtonGroup langGroup = new ButtonGroup();
		
		ActionListener selectLanguage = new ActionListener() 
		{
			public void actionPerformed( ActionEvent event ) 
			{
				String name = ( ( Component ) event.getSource()).getName() + ".txt";
				
				//Root.setLang( name );
			}
		};
		
		for( int i = 0; i < langFiles.length; i++ )
		{
			String filename = langFiles[ i ].getName().substring( 0, langFiles[ i ].getName().lastIndexOf( "." ) );
			
			JRadioButton radioButton = new JRadioButton( filename );
			
			radioButton.setSize( getWidth(), 25 );
			
			languagePanel.add( radioButton );
			langGroup.add( radioButton );
			
			//Root.log( langFiles[ i ].getName() );
		}
		
		
		JRadioButton radioButton1 = new JRadioButton( Root.lang( "LABEL_INASnetServer" ) );
		radioButton1.setSize( getWidth(), 25 );
		radioButton1.setSelected( true );
		//radioButton1.setPreferredSize( new Dimension( getWidth(), 25 ) );
		connectionPanel.add( radioButton1 );
		
		mSelectServerAddress = new JRadioButton( Root.lang( "LABEL_AnotherServer" ) );
		mSelectServerAddress.setSize( getWidth(), 25 );
		mSelectServerAddress.setToolTipText( Root.lang( "LABEL_EnterServerAddress" ) );
		
		ActionListener selectServerAddress = new ActionListener() 
		{
			public void actionPerformed( ActionEvent event ) 
			{
				if( mSelectServerAddress.isSelected() )
				{
					mServerAddress.setEnabled( true );
				}
				else
				{
					mServerAddress.setEnabled( false );
				}
			}
		};
		
		radioButton1.addActionListener( selectServerAddress );
		mSelectServerAddress.addActionListener( selectServerAddress );
		
		
		connectionPanel.add( mSelectServerAddress );
		connectionPanel.add( mServerAddress );
		
		
		group.add( radioButton1 );
		group.add( mSelectServerAddress );
		
		
		
		
		/*
		 * Tab
		 */
		
		
		JTabbedPane tabbedPane = new JTabbedPane();
		
		tabbedPane.addTab( Root.lang( "MAIN_Menu_Settings_Contacts" ), contactsPanel );
		
		
		
		
		tabbedPane.addTab( Root.lang( "MAIN_Menu_Settings_Connection" ), connectionPanel );
		
		tabbedPane.addTab( Root.lang( "MAIN_Menu_Settings_Language" ), languagePanel );

		getContentPane().add( tabbedPane );
	}
	
	JTextField mServerAddress;
	
	JRadioButton mSelectServerAddress;
}